class Enemy {

    enemyTexture = new Image();

    avatar = new renderer.Bitmap(0, 0, this.enemyTexture);


    name = "";

    attack = 0;

    exp = 0;

    x = 0;

    y = 0;

    id = 0;

    constructor() {

    }



    parseFromConfig(config: any) {
        this.id = config.id;
        this.name = config.name;
        this.attack = config.attack;
        this.exp = config.exp;


        // this.enemyTexture.src = config.avatar;
        // this.avatar.image = this.enemyTexture;
        // this.npcTexture.src = config.portrait;
        // this.avatar.image = this.portraitTexture;


    }

    createEnemy(enemy: Enemy) {
        for (let enemy of enemyManager.enemies) {
            if (enemy.id == enemy.id) {
                enemy.avatar = enemy.avatar;
                enemy.name = enemy.name;
                enemy.attack = enemy.attack;
                enemy.exp = enemy.exp;


            }
        }
    }


    toString() {
        return `[ENEMY: id:${this.id}]`
    }
}

class EnemyManager extends EventDispatcher {

    enemies: Enemy[] = [];

    constructor() {
        super();
    }


    parseFromConfig(config: any) {
        for (let enemy of config.enemy) {
            const enemy = new Enemy();
            enemy.parseFromConfig(enemy);
            enemyManager.enemies.push(enemy);
        }
    }




}


const enemyManager = new EnemyManager();